using System;
using System.Collections.Generic;
using System.Text;
using Utility;
using Entites;
using DAL;

namespace BUS
{
  public  class CTDonHangBUS
    {
       public static void Insert(CTDonHang ctdh)
        {
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            ctdhDAL.Insert(ctdh);
        }
        public static void Update(CTDonHang ctdh)
        {
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            ctdhDAL.Update(ctdh);
        }
        public static void Delete(int iD)
        {
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            ctdhDAL.Delete(iD);
        }
        public static tbCTDonHangCollection Get(string where,
            int pageindex,
            int pagesize,
            string orderby,
            string orderdirection,
            out int total)
        {
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            return ctdhDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbCTDonHangCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            return ctdhDAL.Get(cri.Criter, 0, 0, tbCTDonHangColumns.MaDH.ToString(), OrderDirection.ASC.ToString(), out total);
        }
       public static CTDonHang GetByID(int iD)
       {
           int total = 0;
           Criteria cri = new Criteria();
           cri.add(Condition.AND, tbCTDonHangColumns.MaDH.ToString(), Condition.EQUAL, iD);
           CTDonHangDAL ctdhDAL = new CTDonHangDAL();
           tbCTDonHangCollection chitietdonhangcollection = ctdhDAL.Get(cri.Criter,
                 0, 0, tbCTDonHangColumns.MaDH.ToString(), OrderDirection.ASC.ToString(), out total);
           if (chitietdonhangcollection.Count > 0)
               return chitietdonhangcollection[0];
           return null;
       }
      
        public static tbCTDonHangCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            return ctdhDAL.Get(cri.Criter, 1, number,
             tbCTDonHangColumns.MaDH.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbCTDonHangCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            return ctdhDAL.Get(cri.Criter, 1, number,
               tbCTDonHangColumns.MaDH.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
    

}
